package app

import (
	"fmt"
	"poem-server/api"
	"poem-server/comm/global"
	"poem-server/initialize/config"
	"poem-server/initialize/db"
	"poem-server/initialize/log"
	"poem-server/initialize/storage"
	"poem-server/initialize/validator"
)

type LoadApp interface {
	Load()
}

var loadList []LoadApp

func loading() {
	fmt.Println("项目开始加载启动项")
	// TODO 1.加载yaml配置
	loadList = append(loadList, config.NewServerConfig()) //需要先加载,因为后续的应用需要用到配置信息才能启动

	loadList = append(loadList, validator.NewValidatorApp()) //加载自定义验证器

	loadList = append(loadList, storage.NewStorageApp()) // 加载图片文件上传组件

	loadList = append(loadList, log.NewLogApp()) //加载日志组件

	loadList = append(loadList, db.NewDbApp()) //加载数据库 mysql  redis elasticsearch

	loadList = append(loadList, api.NewRouter()) //路由需要最后加载
}

func Start() {
	loading()
	for _, item := range loadList {
		item.Load()
		if global.App.Log != nil {
			global.App.Log.Info("log init success")
		}
	}

}
